package com.intelligentclass.services;

import com.intelligentclass.entity.Comment;
import com.intelligentclass.repositories.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class CommentService {

    private final CommentRepository commentRepository;

    @Autowired
    public CommentService(CommentRepository commentRepository) {
        this.commentRepository = commentRepository;
    }

    public Comment saveComment(Comment comment) {
        return commentRepository.save(comment);
    }


    public List<Comment> findAllComments() {
        return commentRepository.findAll();
    }

    public List<Comment> findCommentsByCid(String cid) {
        return commentRepository.findByCommentCid(cid); // 假设你在 CommentRepository 中有这个方法
    }

    public Comment findCommentByCommentId(Integer commentId) {
        return commentRepository.findByCommentId(commentId);
    }

    public List<Comment> searchCommentsByQueryAndCid(String query, String cid) {
        // 调用 Repository 方法，模糊匹配评论内容并限定课程 ID
        return commentRepository.findByCommentTextContainingAndCommentCid(query, cid);
    }


}
